package com.chinasoft.hm_router_master.slice;

import com.chinasoft.hm_router_master.ResourceTable;
import com.lzh.nonview.router.extras.RouteBundleExtras;

import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.IntentParams;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.utils.net.Uri;

/**
 * ResultAbilitySlice
 *
 * @author:wjt
 * @since 2021-03-20
 */
public class ResultAbilitySlice extends AbilitySlice {
    /**
     * 返回码
     */
    public static final int REQUEST_CODE = 300;
    private Uri uri = null;
    private RouteBundleExtras extras = null;
    private IntentParams intentParams = null;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        uri = intent.getSequenceableParam("uri");
        extras = intent.getSequenceableParam("extras");
        intentParams = intent.getParam("extrasIntentPararms");
        super.setUIContent(ResourceTable.Layout_ability_result);
        /**
        * 销毁页面不返回数据
        */
        Button button = (Button) findComponentById(ResourceTable.Id_backWithoutIntent);
        button.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                getAbility().terminateAbility();
            }
        });
        /**
        * 销毁页面并返回数据
        */
        Button button2 = (Button) findComponentById(ResourceTable.Id_backWithIntent);
        button2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                intent.setParam("value", "返回数据");
                getAbility().setResult(REQUEST_CODE, intent);
                getAbility().terminateAbility();
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
